package it.fuesi.synoutils.model.config;

import android.content.SharedPreferences;

/**
 * Created by pascotto on 20/10/14.
 */
public class SynoConfig {

    private static final int PROTOCOL_HTTP = 0;
    private static final int PROTOCOL_HTTPS = 1;

    private String host;
    private int port;
    private String protocol;
    private String user;
    private String password;

    public static SynoConfig factory(SharedPreferences prefs){
        final SynoConfig config = new SynoConfig();
        config.setHost(prefs.getString("syno_host", null));
        config.setPort(Integer.parseInt(prefs.getString("syno_port", "-1")));
        config.setProtocol(prefs.getString("syno_protocol", null));
        config.setUser(prefs.getString("syno_user", null));
        config.setPassword(prefs.getString("syno_password", null));
        return config;
    }

    public boolean isSet(){
        return protocol != null && !protocol.isEmpty() && host != null && !host.isEmpty() && port > -1 && user != null && !user.isEmpty() && password != null && !password.isEmpty();
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getProtocol() {
        return protocol;
    }

    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getProtocolString(){
        /*
        if(protocol == PROTOCOL_HTTP) return "http";
        if(protocol == PROTOCOL_HTTPS) return "https";
        return null;*/
        return this.protocol;
    }

    @Override
    public String toString() {
        return getProtocolString() + "://" + host + ":" + port + " - user:" + user + " password:" + password;
    }
}
